package patrol.mobile.com.mobilepatrol.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.bean.GridViewAddTitleBean;

/**
 * Created by K on 2018/9/7.
 * des: 首页三个gridview适配器
 */
public class MainPageGridAdapter extends BaseAdapter {

    private Context mContext;
    private List<GridViewAddTitleBean> list;
    private int[] imgs = new int[]{R.mipmap.xingzhengguanli, R.mipmap.yanghuguanli, R.mipmap.jiankongguanli, R.mipmap.anbaoguanli, R.mipmap.anbaoguanli};

    public MainPageGridAdapter(Context context) {
        this.mContext = context;
    }

    public void setData(List<GridViewAddTitleBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_main_page, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvChannel.setText(list.get(position).getTitle());
        viewHolder.ivChannel.setImageResource(imgs[position]);
        /*Glide.with(mContext)
                .load("")
                .into(viewHolder.ivChannel);*/
        return convertView;
    }

    class ViewHolder {
        protected ImageView ivChannel;
        protected TextView tvChannel;

        public ViewHolder(View convertView) {
            ivChannel = (ImageView) convertView.findViewById(R.id.iv_channel);
            tvChannel = (TextView) convertView.findViewById(R.id.tv_channel);
        }
    }
}
